package sort

import "fmt"

//冒泡排序

func bubbleTest(arr []int)[]int{
	for i:=0;i<len(arr)-1;i++{
		if arr[i]>arr[i+1]{
			arr[i],arr[i+1] = arr[i+1],arr[i]
		}
	}
	return arr
}

func bubblesort(arr []int) []int  {

	length:= len(arr)
	if length<1{
		return arr
	}else{
		for i:=0;i<length-1;i++{
			isneedexchange := false
			for j:=0;j<length-1-i;j++{
				if arr[j]>arr[j+1]{
					arr[j],arr[j+1] = arr[j+1],arr[j]
					isneedexchange = true
				}
			}
			if !isneedexchange{
				break
			}
			fmt.Println(arr)
		}
	}
	return arr
}